<?php
/**
 * ECTouch Open Source Project
 * ============================================================================
 * Copyright (c) 2012-2014 http://ectouch.cn All rights reserved.
 * ----------------------------------------------------------------------------
 * 文件名称：notify_url.php
 * ----------------------------------------------------------------------------
 * 异步通知处理
 * ----------------------------------------------------------------------------
 * Licensed ( http://www.ectouch.cn/docs/license.txt )
 * ----------------------------------------------------------------------------
 */

/* 访问控制 */
define('IN_ECTOUCH', true);


// $GLOBALS["HTTP_RAW_POST_DATA"]="<xml><appid><![CDATA[wx92485375516f1bc6]]></appid>
// <bank_type><![CDATA[CFT]]></bank_type>
// <cash_fee><![CDATA[1]]></cash_fee>
// <fee_type><![CDATA[CNY]]></fee_type>
// <is_subscribe><![CDATA[N]]></is_subscribe>
// <mch_id><![CDATA[1328603401]]></mch_id>
// <nonce_str><![CDATA[q2poaxkcy3my0z66d9uktgob921hnlfh]]></nonce_str>
// <openid><![CDATA[oFNHhvz615DABtx_kci-rx4Z0Ffk]]></openid>
// <out_trade_no><![CDATA[2016040689298O47]]></out_trade_no>
// <result_code><![CDATA[SUCCESS]]></result_code>
// <return_code><![CDATA[SUCCESS]]></return_code>
// <sign><![CDATA[557AA21F424DEE4B38B5F9F3A7415179]]></sign>
// <time_end><![CDATA[20160406112555]]></time_end>
// <total_fee>1</total_fee>
// <trade_type><![CDATA[APP]]></trade_type>
// <transaction_id><![CDATA[4006592001201604064589432796]]></transaction_id>
// </xml>";



//微信
if(isset($GLOBALS["HTTP_RAW_POST_DATA"])&&!isset($_POST['trade_status']))
{
     //debug
     // file_put_contents('data.xml', $GLOBALS["HTTP_RAW_POST_DATA"].'\n\n', FILE_APPEND);

  	$curlPost=json_decode(json_encode(simplexml_load_string($GLOBALS["HTTP_RAW_POST_DATA"], 'SimpleXMLElement', LIBXML_NOCDATA)), true);
	$str="&a=wxNotify";
}
//支付宝
else if(isset($_POST['trade_status']))
{
	$str="&a=alipayNotifyUrl";
	$curlPost=$_POST;
}
else
{   
    echo 'no-data';
    exit;

}


    $url="http://".$_SERVER['HTTP_HOST']."/app_api/index.php?m=home&c=Respond".$str;



    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_NOBODY, true);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost);
    $return_str = curl_exec($curl);
    curl_close($curl);
    if($return_str)
    echo $return_str;
    else
    echo 'no-data';
    exit;




